package com.wuzheng.wisgo.sanitation.cloud.controller.brand;

import com.wuzheng.wisgo.sanitation.cloud.model.brand.BaBrandCriteria;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.brand.BaBrand;
import com.wuzheng.wisgo.sanitation.cloud.service.brand.BrandService;
import com.wuzheng.wisgo.sanitation.framework.base.controller.BaseController;
import com.wuzheng.wisgo.sanitation.framework.core.protocol.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author：sp
 * @date：Created in 2019-10-09
 * @description：品牌信息控制器
 * @modified By：sp
 * @version: 1.0
 */
@RestController
@RequestMapping("/brand")
@Api(value = "BrandCtrl", tags = "品牌信息接口")
public class BrandCtrl extends BaseController {

    @Autowired
    private BrandService brandService;

    /**
     * 获取品牌信息列表
     */
    @PostMapping(value = "/fetchList")
    @ApiOperation(value = "获取品牌信息列表")
    public Result<List<BaBrand>> list(@RequestBody BaBrandCriteria baBrandCriteria) {
        return this.success(brandService.selectPage(baBrandCriteria));
    }

    /**
     * 新增品牌信息
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增品牌信息")
    public Result<String> add(BaBrand baBrand) {
         brandService.insert(baBrand);
        return this.success("新增成功");
    }

    /**
     * 删除品牌信息
     */
    @PostMapping(value = "/delete/{id}")
    @ApiOperation(value = "删除品牌信息")
    public Result<String> delete(@PathVariable("id") Long id) {
        brandService.deleteById(id);
        return this.success("删除成功");
    }

    /**
     * 修改品牌信息
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改品牌信息")
    public Result<String> update(BaBrand baBrand) {
        brandService.updateById(baBrand);
        return this.success("修改成功");
    }

    /**
     * 获取品牌信息
     */
    @GetMapping(value = "/get/{id}")
    @ApiOperation(value = "获取品牌信息")
    public Result<BaBrand> get(@PathVariable("id") Long id) {
        return this.success(brandService.selectById(id));
    }
}

